package com.pfzy.lib.net.utils;

import android.app.Activity;
import android.app.Dialog;

import com.pfzy.lib.net.ui.HttpDialogManager;
import com.pfzy.lib.net.ui.HttpToastManager;
import com.pfzy.lib.sdk.log.UXLog;

public class UIUtil {
    private static final String TAG = "UIUtil";
    private static Dialog sDialog;
    private static HttpDialogManager sHttpDialogManager;
    private static HttpToastManager sHttpToastManager;

    public static void setDialogManager(HttpDialogManager dialog) {
        if (dialog != null) {
            sHttpDialogManager = dialog;
        }
    }

    public static void removeDialogManager() {
        sHttpDialogManager = null;
    }

    public static void setToastManager(HttpToastManager toast) {
        if (toast != null) {
            sHttpToastManager = toast;
        }
    }

    public static void removeToastManager() {
        sHttpToastManager = null;
    }

    public static void showToast(String message) {
        if (sHttpToastManager == null) {
            UXLog.w(TAG, "showLoadingDialog-->you should give the HttpToastManager instance to showToast");
        } else {
            sHttpToastManager.showToast(message);
        }
    }

    public static void showLoadingDialog(Activity activity) {
        if (sHttpDialogManager == null) {
            UXLog.w(TAG, "showLoadingDialog-->you should give the HttpDialogManager instance to showLoadingDialog");
            return;
        }
        if (sDialog != null) {
            sDialog.dismiss();
        }
        sDialog = sHttpDialogManager.showLoadingDialog(activity);
    }

    public static void cancelLoadingDiaoog() {
        if (sDialog != null) {
            try {
                sDialog.dismiss();
            } catch (Exception e) {
                UXLog.e(TAG, "cancelLoadingDialog error:" + e.getMessage());
                e.printStackTrace();
            } finally {
                sDialog = null;
            }
        }
    }

    public static void showDownloadDialog(Activity activity) { }

    public static void cancelDownloadDiaoog() { }

    public static void setProgress(int progress) { }
}
